import ISocketMessage from '@/model/other/ISocketMessage'
import ICommonSlice from '@/model/slice/ICommonSlice'
import { createSlice, PayloadAction } from '@reduxjs/toolkit'

const initialState: ICommonSlice = {
  rsaPublicKey:
    'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDadmaCaffN63JC5QsMK/+le5voCB4DzOsV9xOBZgGJyqnizh9/UcFkIoRae5rebdWUtnPO4CTgdJbuSvu/TtIIPj9De5/wiJilFAWd1Ve7qGaxxTxqWwFNp7p/FLr0YpMeBjOylds9GyA1cnjIqruNdYv+qRZnseE0Sq2WEZus9QIDAQAB',
  loadMenuFlag: false,
  socketMessage: {} as ISocketMessage,
  socketStatus: false,
}

export const commonSlice = createSlice({
  name: 'commonSlice',
  initialState,
  reducers: {
    setLoadMenuFlag(state, action: PayloadAction<boolean>) {
      state.loadMenuFlag = action.payload
    },
    setSocketMessage(state, action: PayloadAction<ISocketMessage>) {
      state.socketMessage = action.payload
    },
    setSocketStatus(state, action: PayloadAction<boolean>) {
      state.socketStatus = action.payload
    },
  },
})

export const { setLoadMenuFlag, setSocketMessage, setSocketStatus } =
  commonSlice.actions

export default commonSlice.reducer
